package com.ats.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.ats.model.User;
import com.ats.service.JobRecordSerivce_xh;
import com.ats.service.UserSerivce_xh;
import com.ats.serviceimpl.JobRecordSerivceImpl_xh;
import com.ats.serviceimpl.UserServiceImpl_xh;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * 作业记录
 * @author xh
 *
 */
public class FindJobRecordController_xh extends HttpServlet{
	UserSerivce_xh us = new UserServiceImpl_xh();
	JobRecordSerivce_xh jrs =new JobRecordSerivceImpl_xh();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		resp.setCharacterEncoding("utf8");
		HttpSession session =req.getSession();
		PrintWriter  pw = resp.getWriter();
		int page =Integer.parseInt(req.getParameter("page"));
		int rows =Integer.parseInt(req.getParameter("rows"));
		int start =(page-1)*rows;
		int uid =Integer.parseInt(req.getParameter("uid"));
		//获取用户权限
		int ustate =us.getUstateByUid(uid);
		if(ustate==1){
			//老师对应的作业信息回写页面
			int tid =((User)session.getAttribute("user")).getTid();
			JSONObject jso=jrs.findAllJobRecordByTid(tid, start, rows);
			pw.write(jso.toString());
		}else if(ustate==2){
			//学生对应的作业信息回写页面
			int sid =((User)session.getAttribute("user")).getSid();
			JSONObject jso =jrs.findAllJobRecordBySid(sid, start, rows);
			pw.write(jso.toString());
		}
		pw.flush();
		pw.close();	
	}

}
